import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:gameplay_flutter/lib_basemodel/discover/moment_entity.dart';
import 'package:gameplay_flutter/lib_basemodel/user/user.dart';
import 'package:gameplay_flutter/lib_baseview/lib_baseview.dart';
import 'package:gameplay_flutter/lib_baseview/widget/dialogs.dart';
import 'package:gameplay_flutter/lib_im/index.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:gameplay_flutter/lib_user/user_manager.dart';
import 'package:gameplay_flutter/m_discover/post/post_view.dart';
import 'package:gameplay_flutter/m_me/constants/me_assets_constants.dart';
import 'package:gameplay_flutter/m_me/user_deit_page/user_edit_page.dart';
import 'package:gameplay_flutter/m_me/user_details_page/custom_tab_bar_indicator.dart';
import 'package:gameplay_flutter/m_me/user_details_page/user_details_page_controller.dart';
import 'package:ones/ui.dart';

import '../../generated/assets.dart';
import '../../lib_baseview/theme/jr.dart';
import '../../m_chatroom/src/interface/room_page.dart';
import '../../m_discover/player/player_view.dart';
import '../../m_discover/post_detail/post_detail_view.dart';
import '../../resource/language/generated/l10n.dart';

/// 用户详情页面
/// 使用NestedScrollView实现可折叠的头部效果
class UserDetailsPage extends StatefulWidget {
  final String userId;

  const UserDetailsPage({super.key, this.userId = ""});

  @override
  State<UserDetailsPage> createState() => _UserDetailsPageState();
}

class _UserDetailsPageState extends State<UserDetailsPage>
    with SingleTickerProviderStateMixin {
  late final UserDetailsPageController controller;

  /// Tab页控制器
  late TabController _tabController;

  /// 滚动控制器，用于监听滚动位置实现头部折叠效果
  late ScrollController _scrollController;

  /// Tab页标题列表
  final List<String> _tabs = [
    T.current.me1_my_dynamics,
    T.current.me1_my_likes
  ];

  /// 头部是否已折叠的状态标记
  bool _isCollapsed = false;
  bool _isMe = true;

  int mePageNum = 1;
  int likePageNum = 1;

  // 新增一个变量来存储当前的 userId
  late String _currentUserId;

  double get _appBarHeight =>
      kToolbarHeight + MediaQuery.of(context).padding.top;
  double _contentHeight = 309.h; // 默认高度

  @override
  void initState() {
    super.initState();
    controller = Get.put(UserDetailsPageController());
    String meId = UserManager.instance.currentUser?.id.toString() ?? "0";
    debugPrint("meId = $meId");
    _currentUserId = widget.userId.isEmpty ? meId : widget.userId;
    _isMe = meId == _currentUserId;
    controller.getUserDetails(_currentUserId);
    controller.getUserDynamic(_currentUserId, mePageNum);
    if (_isMe) {
      controller.getLikeDynamic(_currentUserId, mePageNum);
    } else {
      controller.getRoomCard(_currentUserId);
    }

    // 初始化滚动控制器
    _scrollController = ScrollController();
    // 初始化Tab控制器
    _tabController = TabController(length: _tabs.length, vsync: this);
    // 添加滚动监听，根据滚动位置更新头部折叠状态
    _scrollController.addListener(() {
      final isCollapsed = _scrollController.hasClients &&
          _scrollController.offset > (300 - kToolbarHeight);
      if (isCollapsed != _isCollapsed) {
        debugPrint("_isCollapsed changed to: $isCollapsed");
        setState(() {
          _isCollapsed = isCollapsed;
        });
      }
    });
    debugPrint("_isCollapsed111 = $_isCollapsed");
  }

  @override
  void dispose() {
    _tabController.dispose();
    _scrollController.dispose();
    super.dispose();
  }

  /// 构建页面主体
  /// 使用NestedScrollView实现头部折叠效果
  /// 包含一个可折叠的AppBar和TabBarView
  @override
  Widget build(BuildContext context) {
    debugPrint("_isCollapsed222 = $_isCollapsed");
    return Obx(() => Scaffold(
          body: Column(
            children: [
              Expanded(
                child: Stack(children: [
                  NestedScrollView(
                    controller: _scrollController,
                    headerSliverBuilder: (context, innerBoxIsScrolled) {
                      return [
                        SliverAppBar(
                          automaticallyImplyLeading: false,
                          expandedHeight: _contentHeight,
                          floating: false,
                          pinned: true,
                          systemOverlayStyle: _isCollapsed
                              ? const SystemUiOverlayStyle(
                            systemNavigationBarColor: Color(0xFFFFFFFF),
                            systemNavigationBarIconBrightness: Brightness.dark,
                            statusBarIconBrightness: Brightness.dark,
                            statusBarBrightness: Brightness.light,
                          )
                              : const SystemUiOverlayStyle(
                            systemNavigationBarColor: Color(0xFFFFFFFF),
                            systemNavigationBarIconBrightness: Brightness.dark,
                            statusBarIconBrightness: Brightness.light,
                            statusBarBrightness: Brightness.dark,
                          ),
                          flexibleSpace:
                              FlexibleSpaceBar(background: LayoutBuilder(
                            builder: (context, constraints) {
                              // 测量内容高度后更新状态
                              WidgetsBinding.instance.addPostFrameCallback((_) {
                                if (!_isMe) {
                                  final height = context.size?.height ?? 309.h;
                                  if (height != _contentHeight &&
                                      _contentHeight == 309.h) {
                                    setState(() => _contentHeight = height);
                                  }
                                }
                              });
                              return Obx(() =>
                                  _buildUserInfoSection(controller.user.value));
                            },
                          )),
                          bottom: PreferredSize(
                            preferredSize: Size.fromHeight(_isMe ? 67.h : 25.h),
                            child: Container(
                              height: _isMe ? 67.h : 25.h,
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.only(
                                  topLeft:
                                      Radius.circular(_isCollapsed ? 0 : 20),
                                  topRight:
                                      Radius.circular(_isCollapsed ? 0 : 20),
                                ),
                              ),
                              child: Column(
                                children: [
                                  SizedBox(
                                    height: 20.h,
                                  ),
                                  if (_isMe)
                                    SizedBox(
                                      height: 30.h,
                                      child: TabBar(
                                        controller: _tabController,
                                        dividerColor: Colors.transparent,
                                        tabs: _tabs
                                            .map((tab) => Tab(text: tab))
                                            .toList(),
                                        labelColor: const Color(0xFF8A72FE),
                                        unselectedLabelColor:
                                            const Color(0xFFC1C1C1),
                                        labelStyle: TextStyle(
                                            fontSize: 16.sp,
                                            fontWeight: FontWeight.bold),
                                        unselectedLabelStyle: TextStyle(
                                          fontSize: 16.sp,
                                          fontWeight: FontWeight.w500,
                                        ),
                                        labelPadding: EdgeInsets.symmetric(
                                            horizontal: 11.5.w),
                                        tabAlignment: TabAlignment.center,
                                        indicator:
                                            const CustomTabBarIndicator(),
                                        // 使用自定义指示器
                                        indicatorSize: TabBarIndicatorSize.tab,
                                      ),
                                    )
                                ],
                              ),
                            ),
                          ),
                        ),
                      ];
                    },
                    body: Container(
                      padding: EdgeInsets.symmetric(horizontal: 15.w),
                      decoration: const BoxDecoration(color: Colors.white),
                      child: TabBarView(
                        controller: _tabController,
                        children: [
                          if (controller.moments.isNotEmpty)
                            _buildDynamics(controller.moments)
                          else
                            _buildDynamicsList(),
                          if (_isMe)
                            if (controller.likeMoments.isNotEmpty)
                              _likeDynamics(controller.likeMoments)
                            else
                              _buildDynamicsList(),
                        ],
                      ),
                    ),
                  ),
                  Positioned(top: 0, left: 0, right: 0, child: _buildAppBar()),
                ]),
              ),
              if (_isMe)
                _meBottomBar()
              else
                Obx(() => _userBottomBar(controller.user.value))
            ],
          ),
        ));
  }

  Widget _buildAppBar() {
    return Container(
      padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
      height: _appBarHeight,
      decoration: BoxDecoration(
        gradient: _isCollapsed
            ? null
            : LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [
                  Colors.black.withOpacity(0.3),
                  Colors.transparent,
                ],
              ),
        color: _isCollapsed ? Colors.white : null,
      ),
      child: Row(
        children: [
          IconButton(
            icon: Icon(
              Icons.arrow_back,
              color: _isCollapsed ? Colors.black : Colors.white,
            ),
            onPressed: () => Navigator.pop(context),
          ),
          Expanded(
            child: Obx(
                () => (controller.user.value.nickname ?? "User Details").text(
                      fontSize: 22.sp,
                      color: _isCollapsed ? Colors.black : Colors.transparent,
                      textAlign: TextAlign.center,
                      weight: TextFontWeight.regular,
                    )),
          ),
          // 添加一个占位的IconButton，保持布局对称
          IconButton(
            icon: Icon(
              Icons.arrow_back,
              color: Colors.transparent,
            ),
            onPressed: null,
          ),
        ],
      ),
    );
  }

  Widget _buildUserInfoSection(User user) {
    List<String> aboutList = user.aboutList ?? [];
    List<String> truncatedAboutList =
        aboutList.sublist(0, aboutList.length > 4 ? 4 : aboutList.length);
    return Container(
      constraints: BoxConstraints(minHeight: 309.h),
      decoration: BoxDecoration(
          image: DecorationImage(
        image: user.pageImgInAudit != null && user.pageImgInAudit!.isNotEmpty
            ? CachedNetworkImageProvider(user.pageImgInAudit!)
            : const AssetImage(MeAssetsConstants.iconEmpty),
        fit: BoxFit.cover,
      )),
      child: Stack(children: [
        // 半透明黑色遮罩层
        Container(
          color: Colors.black.withOpacity(0.2),
        ),
        Padding(
          padding: EdgeInsets.fromLTRB(15.w, 106.h, 20.w, 0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                children: [
                  CircleAvatar(
                    radius: 37.2.r,
                    backgroundImage: user.headPortraitsUrl != null &&
                            user.headPortraitsUrl!.isNotEmpty
                        ? CachedNetworkImageProvider(user.headPortraitsUrl!)
                        : const AssetImage(MeAssetsConstants.iconEmpty),
                  ),
                  SizedBox(width: 14.w),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(height: 2.h),
                        Row(
                          children: [
                            (user.nickname ?? "").text(
                              fontSize: 22.sp,
                              color: Colors.white,
                              weight: TextFontWeight.regular,
                            ),
                            SizedBox(width: 1.w),
                            Container(
                              alignment: Alignment.center,
                              height: 13.66.h,
                              padding: EdgeInsets.symmetric(
                                horizontal: 6.w,
                              ),
                              decoration: BoxDecoration(
                                color: const Color(0xFF9ED1FF),
                                borderRadius: BorderRadius.circular(7.39.r),
                              ),
                              child: 'LV${(user.memberLevel ?? 0).toString()}'
                                  .text(
                                fontSize: 10.sp,
                                color: Colors.white,
                                weight: TextFontWeight.regular,
                              ),
                            ),
                          ],
                        ),
                        'ID:${user.userCode}'.text(
                          fontSize: 14.sp,
                          color: Colors.white,
                          weight: TextFontWeight.regular,
                        ),
                        SizedBox(height: 1.h),
                        (user?.about ?? T.current.me1_signature).text(
                          fontSize: 11.sp,
                          color: Colors.white,
                          weight: TextFontWeight.regular,
                        ),
                      ],
                    ),
                  ),
                ],
              ),
              SizedBox(height: 23.h),
              if (truncatedAboutList != null && truncatedAboutList.isNotEmpty)
                Wrap(
                  alignment: WrapAlignment.start,
                  // 主轴对齐方式
                  runAlignment: WrapAlignment.start,
                  // 轴对齐方式
                  spacing: 8.w,
                  runSpacing: 8.h,
                  children: [
                    T.current.me4_personal_tages.text(
                      fontSize: 12.sp,
                      color: Colors.white,
                      weight: TextFontWeight.regular,
                    ),
                    for (var tag in truncatedAboutList) _buildTag(tag),
                  ],
                ),
              SizedBox(height: 19.h),
              if (!_isMe)
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    _visitorsCount(
                        T.current.me_following, user?.attentions ?? '0'),
                    _visitorsCount(
                        T.current.me_followers, (user?.fans ?? 0).toString()),
                    _visitorsCount(T.current.me_gifts, user?.giftNum ?? '0'),
                  ],
                ),
            ],
          ),
        ),
      ]),
    );
  }

  Widget _visitorsCount(String type, String count) {
    return Column(
      children: [
        Text(
          count,
          style: TextStyle(fontSize: 18.sp, color: Colors.white),
        ),
        Text(
          type,
          style: TextStyle(fontSize: 12.sp, color: Color(0xFFD8D8D8)),
        ),
      ],
    );
  }

  /// 构建标签组件
  /// @param text 标签文本
  /// @return 返回一个带有圆角背景的标签组件
  Widget _buildTag(String text) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 3.h),
      decoration: BoxDecoration(
        color: const Color(0x66E2DCFF),
        borderRadius: BorderRadius.circular(16),
      ),
      child: text.text(
        fontSize: 12.sp,
        weight: TextFontWeight.regular,
        color: Colors.white,
      ),
    );
  }

  /// 构建动态列表
  /// 返回一个包含用户动态卡片的列表视图
  Widget _buildDynamicsList() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Image.asset(
          MeAssetsConstants.iconEmpty,
          fit: BoxFit.contain,
          width: 248.w,
          height: 248.h,
        ),
        Text(T.current.room15_requires_homeowner,
            style: TextStyle(fontSize: 12.sp, color: Color(0xFFC1C1C1)))
      ],
    );
  }

  Widget _buildDynamics(List<MomentEntity> moments) {
    debugPrint("moments.size = ${moments.length}");
    return EasyRefresh(
      onRefresh: () async {
        mePageNum = 1;
        await controller.getUserDynamic(_currentUserId, mePageNum);
      },
      onLoad: () async {
        mePageNum++;
        await controller.getUserDynamic(_currentUserId, mePageNum);
      },
      header: const ClassicHeader(
        showText: false,
      ),
      footer: const ClassicFooter(
        showText: false,
      ),
      child: MasonryGridView.count(
        padding: EdgeInsets.zero,
        crossAxisCount: 2,
        mainAxisSpacing: 5.h,
        crossAxisSpacing: 4.w,
        itemCount: moments.length,
        itemBuilder: (context, index) {
          var moment = moments[index];
          return Stack(
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      if (moment.cover != null)
                        // Image.network(moment.cover!,fit: BoxFit.fitWidth,).expanded(),
                        CachedNetworkImage(
                          imageUrl: moment.cover!,
                          fit: BoxFit.fitWidth,
                        ).expanded(),
                    ],
                  ).maxHeight(220),
                  Text(moment.titleStr)
                      .marginOnly(top: 4, left: 7, right: 7, bottom: 10),
                  Row(
                    children: [
                      JR
                          .img(moment.userHeadUrl,
                              fit: BoxFit.cover, width: 18, height: 18)
                          .roundedRect(90)
                          .marginOnly(left: 7, right: 5),
                      Text(moment.userNickname)
                          .fontSize(12)
                          .colorInt(0xffC1C1C1),
                      Spacer(),
                      Image.asset(
                              moment.isLike
                                  ? Assets.discoverStar
                                  : Assets.discoverStarGrey,
                              width: 15,
                              height: 15)
                          .marginRight(1),
                      Text(moment.likes.toString())
                          .fontSize(12)
                          .colorInt(0xffC1C1C1)
                          .marginRight(12),
                    ],
                  ).marginBottom(7),
                ],
              ).backgroundColor(Colors.white).roundedRect(8).onClick(() async {
                if (moment.type == 1) {
                  var res = await Get.to(() => PostDetailPage(),
                      arguments: {"moment": moment});
                }
                if (moment.type == 2) {
                  Get.to(() => PlayerPage(), arguments: {"moment": moment});
                }
              }),
              if (_isMe)
                Padding(
                  padding: EdgeInsetsDirectional.only(start: 9.w, top: 7.h),
                  child: Image.asset(
                    MeAssetsConstants.iconFunction,
                    width: 20,
                    height: 20,
                    fit: BoxFit.cover,
                  ),
                ).onClick(() {
                  _showFunctionDialog(context, moment.id.toString());
                }),
              if (moment.type == 2)
                Padding(
                  padding: EdgeInsetsDirectional.only(top: 8.h, end: 8.w),
                  child: Row(
                    children: [
                      const Spacer(),
                      JR.img(Assets.discoverPlay, width: 18.w, height: 18.h),
                    ],
                  ),
                )
            ],
          );
        },
      ),
    );
  }

  Widget _likeDynamics(List<MomentEntity> moments) {
    return EasyRefresh(
      onRefresh: () async {
        likePageNum = 1;
        await controller.getLikeDynamic(_currentUserId, mePageNum);
      },
      onLoad: () async {
        likePageNum++;
        await controller.getLikeDynamic(_currentUserId, mePageNum);
      },
      header: const ClassicHeader(
        showText: false,
      ),
      footer: const ClassicFooter(
        showText: false,
      ),
      child: MasonryGridView.count(
        padding: EdgeInsets.zero,
        crossAxisCount: 2,
        mainAxisSpacing: 5.h,
        crossAxisSpacing: 4.w,
        itemCount: moments.length,
        itemBuilder: (context, index) {
          var moment = moments[index];
          return Stack(
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      if (moment.cover != null)
                        CachedNetworkImage(
                          imageUrl: moment.cover!,
                          fit: BoxFit.fitWidth,
                        ).expanded(),
                    ],
                  ).maxHeight(220),
                  Text(moment.titleStr)
                      .marginOnly(top: 4, left: 7, right: 7, bottom: 10),
                  Row(
                    children: [
                      JR
                          .img(moment.userHeadUrl,
                              fit: BoxFit.cover, width: 18, height: 18)
                          .roundedRect(90)
                          .marginOnly(left: 7, right: 5),
                      Text(moment.userNickname)
                          .fontSize(12)
                          .colorInt(0xffC1C1C1),
                      Spacer(),
                      Image.asset(
                              moment.isLike
                                  ? Assets.discoverStar
                                  : Assets.discoverStarGrey,
                              width: 15,
                              height: 15)
                          .marginRight(1),
                      Text(moment.likes.toString())
                          .fontSize(12)
                          .colorInt(0xffC1C1C1)
                          .marginRight(12),
                    ],
                  ).marginBottom(7),
                ],
              ).backgroundColor(Colors.white).roundedRect(8).onClick(() async {
                if (moment.type == 1) {
                  var res = await Get.to(() => PostDetailPage(),
                      arguments: {"moment": moment});
                }
                if (moment.type == 2) {
                  Get.to(() => PlayerPage(), arguments: {"moment": moment});
                }
              }),
              if (moment.type == 2)
                Padding(
                  padding: EdgeInsetsDirectional.only(top: 8.h, end: 8.w),
                  child: Row(
                    children: [
                      const Spacer(),
                      JR.img(Assets.discoverPlay, width: 18.w, height: 18.h),
                    ],
                  ),
                )
            ],
          );
        },
      ),
    );
  }

  Widget _meBottomBar() {
    return Container(
      color: Colors.white,
      height: 70.h,
      child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
        Container(
          width: 140.w,
          height: 40.h,
          decoration: BoxDecoration(
            gradient: const LinearGradient(
              colors: [Color(0xCC6549EC), Color(0xCC8A72FE)], // 渐变色
              begin: Alignment.centerLeft, // 渐变起点
              end: Alignment.centerRight, // 渐变终点
            ),
            borderRadius: BorderRadius.circular(22.r), // 设置圆角
          ),
          child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
            Image.asset(
              MeAssetsConstants.iconEdit,
              width: 26.w,
              height: 26.h,
            ),
            SizedBox(width: 7.w),
            T.current.me_edit.text(
                color: Colors.white,
                fontSize: 18.sp,
                weight: TextFontWeight.medium),
          ]),
        ).onClick(() {
          Get.to(() => UserEditPage());
        }),
        SizedBox(width: 21.w),
        Container(
          width: 140.w,
          height: 40.h,
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: [Color(0xCC6549EC), Color(0xCC8A72FE)], // 渐变色
              begin: Alignment.centerLeft, // 渐变起点
              end: Alignment.centerRight, // 渐变终点
            ),
            borderRadius: BorderRadius.circular(22.r), // 设置圆角
          ),
          child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
            Image.asset(
              MeAssetsConstants.iconPost,
              width: 26.w,
              height: 26.h,
            ),
            SizedBox(width: 7.w),
            T.current.discover4_post.text(
                color: Colors.white,
                fontSize: 18.sp,
                weight: TextFontWeight.medium),
          ]),
        ).onClick(() {
          Get.to(() => PostPage())?.then((value) {
            mePageNum = 1;
            controller.getUserDynamic(_currentUserId, mePageNum);
          });
        }),
      ]),
    );
  }

  Widget _userBottomBar(User user) {
    var roomNum = controller.roomCard.value.roomNo ?? "0";
    return Container(
      color: Colors.white,
      height: 70.h,
      padding: EdgeInsetsDirectional.only(top: 15.h),
      child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: EdgeInsetsDirectional.only(end: 16.w),
              child: Column(children: [
                Image.asset(
                  roomNum == "0"
                      ? MeAssetsConstants.iconChatRoom0
                      : MeAssetsConstants.iconChatRoom,
                  width: 30.w,
                  height: 30.h,
                  fit: BoxFit.cover,
                ),
                T.current.room10_join_room.text(
                  color: roomNum == "0"
                      ? const Color(0xFFBAB5D8)
                      : const Color(0xFF6549EC),
                  fontSize: 12.sp,
                  weight: TextFontWeight.regular,
                ),
              ]),
            ).onTap(() {
              if (roomNum != "0") {
                RoomPage.show(context, roomNum);
              }
            }),
            Container(
              width: 120.w,
              height: 40.h,
              decoration: BoxDecoration(
                gradient: const LinearGradient(
                  colors: [Color(0xCC6549EC), Color(0xCC8A72FE)], // 渐变色
                  begin: Alignment.centerLeft, // 渐变起点
                  end: Alignment.centerRight, // 渐变终点
                ),
                borderRadius: BorderRadius.circular(22.r), // 设置圆角
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Image.asset(
                    MeAssetsConstants.iconChat,
                    width: 26.w,
                    height: 26.h,
                  ),
                  SizedBox(width: 6.w),
                  T.current.me1_chat.text(
                      color: Colors.white,
                      fontSize: 18.sp,
                      weight: TextFontWeight.medium),
                ],
              ),
            ).onClick(() {
              if (user.imId != null && user.imId!.isNotEmpty) {
                ImManager.jumpChat(user.imId!);
              }
            }),
            SizedBox(width: 9.w),
            Container(
              width: 126.w,
              height: 40.h,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  colors: user.isAttention ?? false
                      ? [const Color(0xCCBFB8E4), const Color(0xCCDBD6F0)]
                      : [const Color(0xCC6549EC), const Color(0xCC8A72FE)],
                  // 渐变色
                  begin: Alignment.centerLeft,
                  // 渐变起点
                  end: Alignment.centerRight, // 渐变终点
                ),
                borderRadius: BorderRadius.circular(22.r), // 设置圆角
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Image.asset(
                    user.isAttention ?? false
                        ? MeAssetsConstants.iconUnfollow
                        : MeAssetsConstants.iconFollow,
                    width: 26.w,
                    height: 26.h,
                  ),
                  SizedBox(width: 2.w),
                  (user.isAttention ?? false
                          ? T.current.discover3_unfollow
                          : T.current.discover3_followed)
                      .text(
                          color: Colors.white,
                          fontSize: 18.sp,
                          weight: TextFontWeight.medium),
                ],
              ),
            ).onClick(() {
              String userId = user.userId?.toString() ?? "";
              bool isAttention = user.isAttention ?? false;
              controller.isAttention(userId, isAttention);
            }),
          ]),
    );
  }

  _showFunctionDialog(BuildContext context, String id) {
    showModalBottomSheet(
        context: context,
        backgroundColor: Colors.white,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(18.r),
            topRight: Radius.circular(18.r),
          ),
        ),
        builder: (BuildContext context) {
          return Column(mainAxisSize: MainAxisSize.min, children: [
            Container(
              alignment: Alignment.center,
              padding: EdgeInsetsDirectional.only(top: 27.h, bottom: 18.h),
              child: T.current.c_delete.text(
                color: Colors.black,
                fontSize: 20.sp,
                weight: TextFontWeight.regular,
              ),
            ).onClick(() {
              controller.deleteDynamic(id).then((value) {
                Navigator.pop(context);
              });
            }),
            Divider(
              height: 10.h,
              thickness: 10.h,
              color: const Color(0xFFFAFAFA),
            ),
            Container(
              alignment: Alignment.center,
              padding: EdgeInsetsDirectional.only(top: 20.h, bottom: 28.h),
              child: T.current.me_edit_cancel.text(
                color: const Color(0xFFA8A8A8),
                fontSize: 22.sp,
                weight: TextFontWeight.regular,
              ),
            ).onClick(() {
              Navigator.pop(context);
            }),
          ]);
        });
  }
}
